import Vue from 'vue'
import Vuex from 'vuex'
import persistedState from 'vuex-persistedstate'
import * as Cookies from 'js-cookie'
Vue.use(Vuex)


const store = new Vuex.Store({
	state:{//相当于data
		token: '',
		user:{},
		userList:[]
	},
	mutations:{//相当于method
	//使用方法：this.$store.commit('SET_TOKEN',参数)
	    SET_TOKEN: (state,token)=>{
			state.token = token
		},
		SET_USER:(state,user)=>{
			state.user = user
		},
		SET_USERLIST:(state,userList)=>{
			state.userList = userList
		}

	},
	getters:{
		//用法：this.$store.getters.getCount
		getToken(){
			return store.state.token
		},
		getUser(){
			return store.state.user
		},
		getUserList(){
			return store.state.userList
		}
	},
	actions: {
	},
	modules: {
	},
	plugins: [
	  persistedState({
		storage: {
		  getItem: key => Cookies.get(key),
		  setItem: (key, value) => Cookies.set(key, value, { expires: 7 }),
		  removeItem: key => Cookies.remove(key)
		}
	  })
	]
})


export default store